<?php
class pekerjaan extends MY_Controller{
    function pekerjaan(){
        parent::MY_Controller();
        $this->data['title'] = "Master Data Pekerjaan";
        $this->load->model('m_pekerjaan');
    }
    
    var $data;
    function index(){
        $this->data['content'] = "pekerjaan/v_pekerjaan";
        $this->data['listPekerjaan'] = $this->m_pekerjaan->getListPekerjaan();
        $this->render($this->data);
    }
    function add_pekerjaan_form(){
        $this->data['content'] = "pekerjaan/v_pekerjaan";
        $this->data['subLink'] = "pekerjaan/add_pekerjaan_proses";
        $this->data['formTitle'] = "Form Tambah Data Pekerjaan";
        $this->data['formView'] = "pekerjaan/addPekerjaanForm";
        $this->data['listPekerjaan'] = $this->m_pekerjaan->getListPekerjaan();
        $this->render($this->data);
    }
    function edit_pekerjaan_form($id){
        $this->data['content'] = "pekerjaan/v_pekerjaan";
        $this->data['subLink'] = "pekerjaan/edit_pekerjaan_proses";
        $this->data['formTitle'] = "Form Edit Data Pekerjaan";
        $this->data['formView'] = "pekerjaan/editPekerjaanForm";    
        $this->data['dataInput'] = $this->m_pekerjaan->getPekerjaanById($id);
        $this->data['listPekerjaan'] = $this->m_pekerjaan->getListPekerjaan();
        $this->render($this->data);
    }
    function add_pekerjaan_proses(){
        $data = array('nama' => $this->input->post('nama'));
        $insert = $this->m_pekerjaan->addPekerjaan($data);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("pekerjaan");
    }
    function edit_pekerjaan_proses(){
        $data = array('id' => $this->input->post('id'),
            'nama' => $this->input->post('nama'));
        $update = $this->m_pekerjaan->editPekerjaan($data);
        if($update == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("pekerjaan");
    }
    function delete_pekerjaan($id){
        $delete = $this->m_pekerjaan->deletePekerjaan($id);
        if($delete == TRUE){
            $this->session->set_flashdata("message",3);
        }else{
            $this->session->set_flashdata("message",4);
        }
        
        redirect("pekerjaan");
    }
}
?>
